import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: '',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    name: 'system',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'admin',
        name: 'Admin',
        component: () => import('@/views/admins'),
        meta: { title: '管理员管理', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/house',
    component: Layout,
    redirect: '/house',
    name: 'House',
    meta: { title: '信息管理', icon: 'el-icon-s-tools'},
    children: [
      {
        path: 'rent',
        name: 'Rent',
        component: () => import('@/views/rent'),
        meta: { title: '租房管理', icon: 'el-icon-menu' }
      },
      {
        path: 'newhouse',
        name: 'Newhouse',
        component: () => import('@/views/newhouse'),
        meta: { title: '出售新房', icon: 'el-icon-menu' }
      },
      {
        path: 'oldhouse',
        name: 'Oldhouse',
        component: () => import('@/views/oldhouse'),
        meta: { title: '二手房', icon: 'el-icon-menu' }
      },
      /* {
        path: 'emp',
        name: 'Emp',
        component: () => import('@/views/emp'),
        meta: { title: '出售管理', icon: 'el-icon-user-solid' }
      }, */
      {
        path: 'estate',
        name: 'Estate',
        component: () => import('@/views/estate'),
        meta: { title: '小区管理', icon: 'el-icon-menu' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
